﻿using System;
using System.Diagnostics;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.GameContent.UI.Elements;
using Terraria.Localization;
using Terraria.UI;
using Terraria.UI.Gamepad;

namespace Terraria.ModLoader.UI
{
	// Token: 0x020002A0 RID: 672
	internal class UIModInfo : UIState
	{
		// Token: 0x06001AD6 RID: 6870 RVA: 0x0042C714 File Offset: 0x0042A914
		public override void OnInitialize()
		{
			this.uIElement = new UIElement();
			this.uIElement.Width.Set(0f, 0.8f);
			this.uIElement.MaxWidth.Set(600f, 0f);
			this.uIElement.Top.Set(220f, 0f);
			this.uIElement.Height.Set(-220f, 1f);
			this.uIElement.HAlign = 0.5f;
			UIPanel uipanel = new UIPanel();
			uipanel.Width.Set(0f, 1f);
			uipanel.Height.Set(-110f, 1f);
			uipanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
			this.uIElement.Append(uipanel);
			this.modInfo = new UIMessageBox("This is a test of mod info here.");
			this.modInfo.Width.Set(-25f, 1f);
			this.modInfo.Height.Set(0f, 1f);
			uipanel.Append(this.modInfo);
			UIScrollbar uiscrollbar = new UIScrollbar();
			uiscrollbar.SetView(100f, 1000f);
			uiscrollbar.Height.Set(-20f, 1f);
			uiscrollbar.VAlign = 0.5f;
			uiscrollbar.HAlign = 1f;
			uipanel.Append(uiscrollbar);
			this.modInfo.SetScrollbar(uiscrollbar);
			this.uITextPanel = new UITextPanel<string>(Language.GetTextValue("tModLoader.ModInfoHeader"), 0.8f, true);
			this.uITextPanel.HAlign = 0.5f;
			this.uITextPanel.Top.Set(-35f, 0f);
			this.uITextPanel.SetPadding(15f);
			this.uITextPanel.BackgroundColor = new Color(73, 94, 171);
			this.uIElement.Append(this.uITextPanel);
			this.modHomepageButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.ModInfoVisitHomepage"), 1f, false);
			this.modHomepageButton.Width.Set(-10f, 1f);
			this.modHomepageButton.Height.Set(25f, 0f);
			this.modHomepageButton.VAlign = 1f;
			this.modHomepageButton.Top.Set(-65f, 0f);
			this.modHomepageButton.OnMouseOver += UICommon.FadedMouseOver;
			this.modHomepageButton.OnMouseOut += UICommon.FadedMouseOut;
			this.modHomepageButton.OnClick += this.VisitModHomePage;
			this.uIElement.Append(this.modHomepageButton);
			UITextPanel<string> uitextPanel = new UITextPanel<string>(Language.GetTextValue("UI.Back"), 1f, false);
			uitextPanel.Width.Set(-10f, 0.333f);
			uitextPanel.Height.Set(25f, 0f);
			uitextPanel.VAlign = 1f;
			uitextPanel.Top.Set(-20f, 0f);
			uitextPanel.OnMouseOver += UICommon.FadedMouseOver;
			uitextPanel.OnMouseOut += UICommon.FadedMouseOut;
			uitextPanel.OnClick += this.BackClick;
			this.uIElement.Append(uitextPanel);
			this.extractButton = new UITextPanel<string>(Language.GetTextValue("tModLoader.ModInfoExtract"), 1f, false);
			this.extractButton.Width.Set(-10f, 0.333f);
			this.extractButton.Height.Set(25f, 0f);
			this.extractButton.VAlign = 1f;
			this.extractButton.HAlign = 0.5f;
			this.extractButton.Top.Set(-20f, 0f);
			this.extractButton.OnMouseOver += UICommon.FadedMouseOver;
			this.extractButton.OnMouseOut += UICommon.FadedMouseOut;
			this.extractButton.OnClick += this.ExtractClick;
			this.uIElement.Append(this.extractButton);
			this.deleteButton = new UITextPanel<string>(Language.GetTextValue("UI.Delete"), 1f, false);
			this.deleteButton.Width.Set(-10f, 0.333f);
			this.deleteButton.Height.Set(25f, 0f);
			this.deleteButton.VAlign = 1f;
			this.deleteButton.HAlign = 1f;
			this.deleteButton.Top.Set(-20f, 0f);
			this.deleteButton.OnMouseOver += UICommon.FadedMouseOver;
			this.deleteButton.OnMouseOut += UICommon.FadedMouseOut;
			this.deleteButton.OnClick += this.DeleteClick;
			this.uIElement.Append(this.deleteButton);
			base.Append(this.uIElement);
		}

		// Token: 0x06001AD7 RID: 6871 RVA: 0x000132EA File Offset: 0x000114EA
		internal void SetModInfo(string text)
		{
			this.info = text;
			if (this.info.Equals(""))
			{
				this.info = Language.GetTextValue("tModLoader.ModInfoNoDescriptionAvailable");
			}
		}

		// Token: 0x06001AD8 RID: 6872 RVA: 0x00013315 File Offset: 0x00011515
		internal void SetModName(string text)
		{
			this.modDisplayName = text;
		}

		// Token: 0x06001AD9 RID: 6873 RVA: 0x0001331E File Offset: 0x0001151E
		internal void SetGotoMenu(int gotoMenu)
		{
			this.gotoMenu = gotoMenu;
		}

		// Token: 0x06001ADA RID: 6874 RVA: 0x00013327 File Offset: 0x00011527
		internal void SetURL(string url)
		{
			this.url = url;
		}

		// Token: 0x06001ADB RID: 6875 RVA: 0x00013330 File Offset: 0x00011530
		internal void SetMod(LocalMod mod)
		{
			this.localMod = mod;
		}

		// Token: 0x06001ADC RID: 6876 RVA: 0x00013339 File Offset: 0x00011539
		private void BackClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(11, -1, -1, 1, 1f, 0f);
			Main.menuMode = this.gotoMenu;
		}

		// Token: 0x06001ADD RID: 6877 RVA: 0x0042CC5C File Offset: 0x0042AE5C
		private void ExtractClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			Interface.extractMod.SetMod(this.localMod);
			Interface.extractMod.SetGotoMenu(this.gotoMenu);
			Main.menuMode = 10019;
		}

		// Token: 0x06001ADE RID: 6878 RVA: 0x0001335B File Offset: 0x0001155B
		private void DeleteClick(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(11, -1, -1, 1, 1f, 0f);
			File.Delete(this.localMod.modFile.path);
			Main.menuMode = this.gotoMenu;
		}

		// Token: 0x06001ADF RID: 6879 RVA: 0x00013392 File Offset: 0x00011592
		private void VisitModHomePage(UIMouseEvent evt, UIElement listeningElement)
		{
			Main.PlaySound(10, -1, -1, 1, 1f, 0f);
			Process.Start(this.url);
		}

		// Token: 0x06001AE0 RID: 6880 RVA: 0x000133B5 File Offset: 0x000115B5
		public override void Draw(SpriteBatch spriteBatch)
		{
			base.Draw(spriteBatch);
			UILinkPointNavigator.Shortcuts.BackButtonCommand = 100;
			UILinkPointNavigator.Shortcuts.BackButtonGoto = this.gotoMenu;
		}

		// Token: 0x06001AE1 RID: 6881 RVA: 0x0042CCA8 File Offset: 0x0042AEA8
		public override void OnActivate()
		{
			this.uITextPanel.SetText(Language.GetTextValue("tModLoader.ModInfoHeader") + this.modDisplayName, 0.8f, true);
			this.modInfo.SetText(this.info);
			if (this.url.Equals(""))
			{
				this.modHomepageButton.Remove();
			}
			else
			{
				this.uIElement.Append(this.modHomepageButton);
			}
			if (this.localMod != null)
			{
				this.uIElement.Append(this.deleteButton);
				this.uIElement.Append(this.extractButton);
				return;
			}
			this.deleteButton.Remove();
			this.extractButton.Remove();
		}

		// Token: 0x04001814 RID: 6164
		internal UIElement uIElement;

		// Token: 0x04001815 RID: 6165
		public UIMessageBox modInfo;

		// Token: 0x04001816 RID: 6166
		public UITextPanel<string> uITextPanel;

		// Token: 0x04001817 RID: 6167
		internal UITextPanel<string> modHomepageButton;

		// Token: 0x04001818 RID: 6168
		internal UITextPanel<string> extractButton;

		// Token: 0x04001819 RID: 6169
		internal UITextPanel<string> deleteButton;

		// Token: 0x0400181A RID: 6170
		private int gotoMenu;

		// Token: 0x0400181B RID: 6171
		private LocalMod localMod;

		// Token: 0x0400181C RID: 6172
		private string url = "";

		// Token: 0x0400181D RID: 6173
		private string info = "";

		// Token: 0x0400181E RID: 6174
		private string modDisplayName = "";
	}
}
